package com.mmlc.meimei.lichengkongjian.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.androidnetframe.utils.DateUtils;
import com.mmlc.inter.InterAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.InformationDataBean;
import com.mmlc.utils.ViewUtils;
import com.mmlc.utils.XUtils;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/7/18.
 */
public class FashionInformationAdapter extends InterAdapter<InformationDataBean> {
    public FashionInformationAdapter(Context context, ArrayList<InformationDataBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_fashion_information, parent, false);

            holder = new ViewHolder();
            holder.tv_title = ViewUtils.getView(convertView, R.id.tv_title);
            holder.tv_time = ViewUtils.getView(convertView, R.id.tv_time);
            holder.iv_content = ViewUtils.getView(convertView, R.id.iv_content);
            holder.tv_content = ViewUtils.getView(convertView, R.id.tv_content);
            holder.ll_more = ViewUtils.getView(convertView, R.id.ll_more);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        InformationDataBean informationDataBean = datas.get(position);

        if (!ViewUtils.isEmpty(informationDataBean.getName()))
            holder.tv_title.setText(informationDataBean.getName());
        if (!ViewUtils.isEmpty(informationDataBean.getAdd_time()))
            holder.tv_time.setText(DateUtils.changeDateStyle(informationDataBean.getAdd_time(), "yyyy-MM-dd HH:mm:ss", "M月d日"));
        XUtils.image(holder.iv_content, informationDataBean.getImg(),
                XUtils.getImageOptionsBuilder().setImageScaleType(ImageView.ScaleType.CENTER_CROP).build());
        if (!ViewUtils.isEmpty(informationDataBean.getDescription())) {
            holder.tv_content.setVisibility(View.VISIBLE);
            holder.tv_content.setText(informationDataBean.getDescription());
        } else holder.tv_content.setVisibility(View.GONE);

        return convertView;
    }

    class ViewHolder {
        ImageView iv_content;
        TextView tv_title, tv_time, tv_content;
        LinearLayout ll_more;
    }
}
